package com.cictec.middleware.gps.engine.thread;

import java.util.Date;

import com.cictec.middleware.core.pojo.MiddlewarePosition;
import com.cictec.middleware.gps.engine.TimeEventBus;
import com.cictec.middleware.gps.engine.position.TerminalPositionEvent;
import com.cictec.middleware.ribbon.loadbalancer.rule.ThreadContextHolder;

/**
 * 接收GPS位置信息事件处理（通过线程处理）
 * @author Administrator
 *
 */
public class PositionExecutorRunable implements Runnable {

	private TimeEventBus timeEventBus;
	private MiddlewarePosition position;

	public PositionExecutorRunable(MiddlewarePosition position, TimeEventBus timeEventBus) {
		this.position = position;
		this.timeEventBus = timeEventBus;
	}

	@Override
	public void run() {
		try {
			ThreadContextHolder.setValue(position.getDevCode(), position.getCityCode());
			TerminalPositionEvent event = new TerminalPositionEvent(position, new Date());
			timeEventBus.post(event);
		} catch (Exception e) {
			// e.printStackTrace();
		}

	}
}
